//
// Created by dave on 18-7-29.
//
#pragma once

#include <string>
#include <algorithm>
#include "../msg_body.h"
#include "../data_utils.h"

class TermRegisterResp : public MsgBody {
public:
    std::vector<char> encode() override {
        std::vector<char> ret;
        write_word(ret, termSeqNo_);
        ret.push_back(result_);
        for_each(auth_.cbegin(), auth_.cend(), [&ret](const char ch) {
            ret.push_back(ch);
        });
        return ret;
    }

    void decode(std::vector<char> data, std::size_t start, std::size_t stop) override {
        termSeqNo_ = read_word(data, start);
        result_ = data[start + 2];
        auth_ = std::string(&data[start + 3], stop - start - 3);
    }

    unsigned short getTermSeqNo() const { return termSeqNo_; }
    void setTermSeqNo(unsigned short termSeqNo) { this->termSeqNo_ = termSeqNo; }

    char getResult() const { return result_; }
    void setResult(char result) { this->result_ = result; }

    std::string getAuth() const { return auth_; }
    void setAuth(std::string auth) { this->auth_ = auth; }

private:
    unsigned short termSeqNo_;
    char result_;
    std::string auth_;
};